package cn.santi.controller;

import cn.santi.domain.Staff;
import cn.santi.emuns.R;
import cn.santi.service.StaffService;
import cn.santi.utli.DateTool;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/staffuser")
public class StaffUserController {
    @Autowired
    private StaffService sff;

    @GetMapping("/addlogin")
    public R addlogin(String name,String pwd){
        System.out.println("name:"+name+"pwd:"+pwd);
        LambdaQueryWrapper<Staff> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Staff::getName,name)
                .eq(Staff::getPwd,pwd);
        Staff staff = sff.getOne(wrapper);
        if (staff!=null){
            staff.setSize(staff.getSize()+1);
            staff.setDate(DateTool.gettime());
            sff.updateById(staff);
            return R.ok(staff);
        }else {
            return R.fail("用户账号不存在");
        }
    }
}
